import java.awt.FlowLayout;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;

/**
 * COPYRIGHT(C) 2008. Natasha Khuri. All Rights Reserved.
 * This class creates a window frame that is centered on the screen.
 * The frame contains one button and a label that changes its text.
 * @author Natasha Khuri
 * @version 1.01 2008-11-23
 *
 */
public class ButtonViewer
{
   public static void main(String[] args)
   {
      //constants for the frame
      final String FRAME_TITLE = "Frame with a button";
      final int FRAME_WIDTH = 250;
      final int FRAME_HEIGHT = 100;

      //constants for the components
      final String BUTTON_TEXT = "Click me";

      JFrame frame = new JFrame();
      frame.setTitle(FRAME_TITLE);

      frame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
      /*
       * this will center the frame on the screen
       * must be called after the setSize method
       */
      frame.setLocationRelativeTo(null);
      frame.setLayout(new FlowLayout());

      JLabel label1 = new JLabel("Click the button");
      frame.add(label1);
      JButton button1 = new JButton(BUTTON_TEXT);
      frame.add(button1);

      ButtonListener listener = new ButtonListener(label1);
      button1.addActionListener(listener );


      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setVisible(true);
   }

}

